/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/12/03
*/
#include "LuaScrollBar.h"
#include "../../utilities/Log.h"

#ifdef EDUI_USE_LUAPLUS

EDUI_NAMESPACE_BEGIN

#define CObjPtr (ScrollBar::ToScrollBar(m_cobj))

void* LuaScrollBar::GetInterface(void* data)
{
    if (!data) return 0;
    LuaScrollBar* scrollBar = new LuaScrollBar((ScrollBar*)data);
#ifdef EDUI_TEST_NEW_DELETE
    ++m_newdeleteNum;
    Log("[LuaScrollBar] new LuaScrollBar : %d, %d", scrollBar, data);
#endif
    return scrollBar;
}

void LuaScrollBar::Release()
{
#ifdef EDUI_TEST_NEW_DELETE
    --m_newdeleteNum;
    Log("[LuaScrollBar] delete LuaScrollBar : %d, %d, %s", this, m_cobj, this->GetName());
#endif
    delete this;
}

LuaScrollBar::LuaScrollBar(ScrollBar* scrollBar) : LuaSlider(scrollBar)
{}

LuaScrollBar::~LuaScrollBar()
{}

//----------------------------------------//

int LuaScrollBar::GetBarBkRect(LuaState *L)
{
    Rect rc = CObjPtr->GetBarBkRect();
    LuaObject obj = LuaBaseNS::ToLuaObj(L, &rc);
    obj.Push(L);
    return 1;
}

int LuaScrollBar::GetButton1Rect(LuaState *L)
{
    Rect rc = CObjPtr->GetButton1Rect();
    LuaObject obj = LuaBaseNS::ToLuaObj(L, &rc);
    obj.Push(L);
    return 1;
}

int LuaScrollBar::GetButton2Rect(LuaState *L)
{
    Rect rc = CObjPtr->GetButton2Rect();
    LuaObject obj = LuaBaseNS::ToLuaObj(L, &rc);
    obj.Push(L);
    return 1;
}

bool LuaScrollBar::SetButton1Size(int w, int h)
{
    Size data(w, h);
    return CObjPtr->SetButton1Size(&data);
}

int LuaScrollBar::GetButton1Size(LuaState *L)
{
    Size sz = CObjPtr->GetButton1Size();
    LuaObject obj = LuaBaseNS::ToLuaObj(L, &sz);
    obj.Push(L);
    return 1;
}

bool LuaScrollBar::SetButton2Size(int w, int h)
{
    Size data(w, h);
    return CObjPtr->SetButton2Size(&data);
}

int LuaScrollBar::GetButton2Size(LuaState *L)
{
    Size sz = CObjPtr->GetButton2Size();
    LuaObject obj = LuaBaseNS::ToLuaObj(L, &sz);
    obj.Push(L);
    return 1;
}

bool LuaScrollBar::SetButton1Inset(int l, int t, int r, int b)
{
    Rect1 data(l ,t, r, b);
    return CObjPtr->SetButton1Inset(&data);
}

int LuaScrollBar::GetButton1Inset(LuaState *L)
{
    Rect1 rc1 = CObjPtr->GetButton1Inset();
    LuaObject obj = LuaBaseNS::ToLuaObj(L, &rc1);
    obj.Push(L);
    return 1;
}

bool LuaScrollBar::SetButton2Inset(int l, int t, int r, int b)
{
    Rect1 data(l ,t, r, b);
    return CObjPtr->SetButton2Inset(&data);
}

int LuaScrollBar::GetButton2Inset(LuaState *L)
{
    Rect1 rc1 = CObjPtr->GetButton2Inset();
    LuaObject obj = LuaBaseNS::ToLuaObj(L, &rc1);
    obj.Push(L);
    return 1;
}

//----------------------------------------//

void LuaScrollBar::Register(LuaState *L)
{
    LuaObject obj = LuaHelperNS::AddToMetas(L, "ScrollBar", "Slider");
    obj.SetObject("__index", obj);
    obj.RegisterDirect("__NewCObj__", &LuaScrollBar::GetInterface);

    obj.RegisterObjectFunctor("GetBarBkRect", &LuaScrollBar::GetBarBkRect);
    obj.RegisterObjectFunctor("GetButton1Rect", &LuaScrollBar::GetButton1Rect);
    obj.RegisterObjectFunctor("GetButton2Rect", &LuaScrollBar::GetButton2Rect);
    obj.RegisterObjectDirect("SetButton1Size", (LuaScrollBar*)0, &LuaScrollBar::SetButton1Size);
    obj.RegisterObjectFunctor("GetButton1Size", &LuaScrollBar::GetButton1Size);
    obj.RegisterObjectDirect("SetButton2Size", (LuaScrollBar*)0, &LuaScrollBar::SetButton2Size);
    obj.RegisterObjectFunctor("GetButton2Size", &LuaScrollBar::GetButton2Size);
    obj.RegisterObjectDirect("SetButton1Inset", (LuaScrollBar*)0, &LuaScrollBar::SetButton1Inset);
    obj.RegisterObjectFunctor("GetButton1Inset", &LuaScrollBar::GetButton1Inset);
    obj.RegisterObjectDirect("SetButton2Inset", (LuaScrollBar*)0, &LuaScrollBar::SetButton2Inset);
    obj.RegisterObjectFunctor("GetButton2Inset", &LuaScrollBar::GetButton2Inset);
}

#undef CObjPtr

EDUI_NAMESPACE_END

#endif